package Prefix_and;

/**
 * Created with Intellij IDEA.
 * Description;
 * User:TQ02
 * Data:2024-01-24
 * Time:19:21
 * Text：除自身以外数组的乘积
 */
public class Text4 {
    public int[] productExceptSelf(int[] nums) {
        int[] F=new int[nums.length];
        int[] G=new int[nums.length];
        for(int i=0;i<nums.length;i++){
            if(i==0){
                F[0]=1;
                continue;
            }
            F[i]=nums[i-1]*F[i-1];
        }
        for(int i=nums.length-1;i>=0;i--){
            if(i==nums.length-1){
                G[i]=1; continue;
            }
            G[i]=nums[i+1]*G[i+1];
        }
        for(int i=0;i<nums.length;i++){
            nums[i]=F[i]*G[i];
        }
        return nums;
    }
}
